﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iNet.Collections
{
	/// <summary>
	/// 唯讀集合。
	/// </summary>
	public class ReadOnlySet<T> : ISet<T>
	{
		#region 欄位
		ISet<T> _BaseSet;
		#endregion
		#region 建構子
		/// <summary>
		/// 初始化新的 ReadOnlySet 執行個體。
		/// </summary>
		/// <param name="baseSet">提供元素讀取的集合。</param>
		/// <exception cref="ArgumentNullException">baseSet 為 Null (Visual Basic 為 Nothing)。</exception>
		public ReadOnlySet(ISet<T> baseSet)
		{
			if (baseSet == null)
				throw new ArgumentNullException("baseSet");
			_BaseSet = baseSet;
		}
		#endregion

		public bool Add(T item)
		{
			throw new InvalidOperationException();
		}

		public void ExceptWith(IEnumerable<T> other)
		{
			throw new InvalidOperationException();
		}

		public void IntersectWith(IEnumerable<T> other)
		{
			throw new InvalidOperationException();
		}

		public bool IsProperSubsetOf(IEnumerable<T> other)
		{
			return _BaseSet.IsProperSubsetOf(other);
		}

		public bool IsProperSupersetOf(IEnumerable<T> other)
		{
			return _BaseSet.IsProperSupersetOf(other);
		}

		public bool IsSubsetOf(IEnumerable<T> other)
		{
			return _BaseSet.IsSubsetOf(other);
		}

		public bool IsSupersetOf(IEnumerable<T> other)
		{
			return _BaseSet.IsSupersetOf(other);
		}

		public bool Overlaps(IEnumerable<T> other)
		{
			return _BaseSet.Overlaps(other);
		}

		public bool SetEquals(IEnumerable<T> other)
		{
			return _BaseSet.SetEquals(other);
		}

		public void SymmetricExceptWith(IEnumerable<T> other)
		{
			throw new InvalidOperationException();
		}

		public void UnionWith(IEnumerable<T> other)
		{
			throw new InvalidOperationException();
		}

		void ICollection<T>.Add(T item)
		{
			throw new InvalidOperationException();
		}

		public void Clear()
		{
			throw new InvalidOperationException();
		}

		public bool Contains(T item)
		{
			return _BaseSet.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			_BaseSet.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get
			{
				return _BaseSet.Count;
			}
		}

		public bool IsReadOnly
		{
			get 
			{
				return true;
			}
		}

		public bool Remove(T item)
		{
			throw new InvalidOperationException();
		}

		public IEnumerator<T> GetEnumerator()
		{
			return _BaseSet.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return _BaseSet.GetEnumerator();
		}
	}
}
